package mytest.ssw.www.myandroidproject.tools;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by 73409 on 2015/11/1.
 */
public class MD5Utils {

    public static String md5password(String password)
    {
        MessageDigest digest = null;
        try {
            digest = MessageDigest.getInstance("md5");

            byte [] bytes =  digest.digest(password.getBytes());
            StringBuffer buffer = new StringBuffer();
            for(byte b: bytes){
                int number = b & 0xff;//加盐
                String hex = Integer.toHexString(number);
                if(hex.length()==1){
                    buffer.append("0");
                }
                buffer.append(hex);
            }
            //md5加密后的值
            System.out.println(buffer);
            return  buffer.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }

    }

}
